<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/13
 * Time: 19:52
 */

namespace App\Http\Controllers;


use App\Http\Eloquent\GameRepository;
use Illuminate\Http\Request;

class ApplyController extends Controller
{
    /**
     * 申请列表
     */
    public function ApplyList()
    {
        //查询申请列表
        $dataMap = GameRepository::getRowsByMap();
        return response(view('apply.index',['datas'=>$dataMap]));
    }

    /**
     * 添加申请
     */
    public function AddProduct(Request $request)
    {
        $class = $request->get('class');

        if(!in_array($class,['0','1','2','3']))return response('',550);

        return response(view("apply.add",['class'=>$class]));
    }

    public function SaveProduct(Request $request){
        $data = $request->all();

        unset($data['_token']);
        if(isset($data['id']))
        {
            if(GameRepository::updateData($data))
            {
                return $this->ApplyList();
            }
        }else{
            if(GameRepository::insertData($data))
            {
                return $this->ApplyList();
            }
        }
        return response('错误',550);
    }


    public function EditProduct(Request $request)
    {
        $productId = $request->get('id');
        if(!$productId)return response('请求错误',550);

        $product = GameRepository::first(['id'=>$productId]);
        if($product){
            $gameExt = $product->gameExt;
            return view('apply.edit',['game'=>$product,'ext'=>$gameExt]);
        }
        return response('产品不存在');

    }
}